package com.haoze.nurse.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.haoze.common.response.Result;
import com.haoze.common.response.ResultGenerator;
import com.haoze.nurse.dto.lab.LabSpecimenSearchDto;
import com.haoze.nurse.service.FileIndexService;
import com.haoze.nurse.service.PatientOrderService;
import com.haoze.nurse.service.PatientService;
import com.haoze.nurse.vo.Commodel;
import com.haoze.nurse.vo.DoctorAdvicesVO;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/nurse/patientInfo")
@Api(value = "护理表单目录")
public class PatientController {

	@Resource
	PatientService patientService;


    @GetMapping("/patientInfoCards")
	@ApiOperation(value = "获取指定病区病人信息卡")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query", example = "1"),
			@ApiImplicitParam(name = "pageSize", value = "页长", dataType = "Integer", paramType = "query", example = "20"),
			@ApiImplicitParam(name = "wardId", value = "病区ID", dataType = "String", paramType = "query", example = "1CD50685DD29416EB58F2E9D9DAC013E")
	})
	public Result getNursePatients(@RequestParam Integer page, @RequestParam Integer pageSize, @RequestParam String wardId,
								   @RequestParam(required = false) String search) {
		return patientService.getPatientInfoCards(page, pageSize, wardId,search);
	}

	@GetMapping("/patientInfo")
	@ApiOperation(value = "获取病人信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "qrCode", value = "二维码编码", dataType = "String", paramType = "query", example = "20200319000050008", required = true)
	})
	public Result getPatientInfo(@RequestParam(required = true) String qrCode) {
		return patientService.getPatientInfo(qrCode);
	}

    @GetMapping("/conditionInfo")
    @ApiOperation(value = "病情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inpatNum", value = "住院号", dataType = "String", paramType = "query", example = "1097434-1", required = true)
    })
    public Result conditionInfo(@RequestParam(required = true) String inpatNum,@RequestParam(required = false) String wardId) {
        return patientService.conditionInfo(inpatNum,wardId);
    }

    @GetMapping("/depts")
	@ApiOperation(value = "获取授权科室或病区")
	public Result getDepts() {
		return patientService.getDepts();
	}


	@GetMapping("/exam")
	@ApiOperation(value = "获取检查列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "inpatNum", value = "住院号", required = true),
			@ApiImplicitParam(name = "page", value = "页码",required = true),
			@ApiImplicitParam(name = "pageSize", value = "页长",required = true),
			@ApiImplicitParam(name = "type", value = "检查状态(空是全部，1，报告已出，2 报告未出)"),
			@ApiImplicitParam(name = "times", value = "检查时间")
	})
	public Result queryExam(
			@RequestParam final String inpatNum,
			@RequestParam Integer page,
			@RequestParam Integer pageSize,
			@RequestParam(required = false) final String type,
			@RequestParam(required = false) final String times) {
		return ResultGenerator.genOkResult(patientService.getExamList(inpatNum, times,type,page,pageSize));
	}


	@GetMapping("/examDetail")
	@ApiOperation(value = "获取检查详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "examItemId", value = "exam_item主键",required = true)
	})
	public Result getExamDetail(@RequestParam String examItemId){

    	return  ResultGenerator.genOkResult(patientService.getExamDetail(examItemId));
	}



	@GetMapping("/lab")
	@ApiOperation(value = "获取检验列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "inpatNum", value = "住院号", required = true),
			@ApiImplicitParam(name = "times", value = "时间"),
			@ApiImplicitParam(name = "page", value = "页码",required = true),
			@ApiImplicitParam(name = "pageSize", value = "页长",required = true),
			@ApiImplicitParam(name = "type", value = "检验状态(空是全部，1，已出报告，2未出报告)"),
	})
	public Result getLab(@RequestParam String inpatNum,
						 @RequestParam Integer page,
						 @RequestParam Integer pageSize,
						 @RequestParam(required = false) String type,
						 @RequestParam(required = false) String times) {
		if (StringUtils.isNotBlank(times)) {
			times += " 23:59:59";
		}
		return ResultGenerator.genOkResult(patientService.getLabList(inpatNum, type, times,page,pageSize));//a
	}

	@GetMapping("/labDetail")
	@ApiOperation(value = "获取检验详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "labItemDataId", value = "PATIENT_LAB_ITEM 主键",required = true)
	})
	public Result getLabDetail(@RequestParam String labItemDataId) {
		return  ResultGenerator.genOkResult(patientService.geLabDetail(labItemDataId));
	}

	@GetMapping("/listPatients")
	@ApiOperation(value = "病人列表,查询全院")
	public Result listPatients(@RequestParam(required = false) String wardId, @RequestParam(required = false) String queryString,
							   @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer pageSize) {
		PageHelper.startPage(page, pageSize);
		List<Map<String, String>> list = patientService.listPatients(wardId, queryString);
		PageInfo<Map<String, String>> pageInfo = new PageInfo<>(list);
		return ResultGenerator.genOkResult(pageInfo);
	}



}
